using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WP.Modules;
using WP.Commons;
using WP.Controls;
using WP.Controls.GridColumn;
using WP.DB;

namespace WP.MF.Form
{
    public partial class frmMMiscKeyMtn : BaseQryRpt 
    {
        #region Define Variable
        private const int intApSwitchNum  = 15;  //the number of a/p switch
        private const int intArSwitchNum  = 31;  //the number of a/r switch
        private const int intImSwitchNum  = 24;  //the number of i/m switch
        private const int intMSwitchNum   = 28;  //the number of system files switch
        private const int intRmSwitchNum = 7;    //the number of remanufacturing switch
        private const int intOeSwitchNum  = 53;  //the number of oe switch
        private const int intPoSwitchNum  = 2;   //the number of po switch
        private SwitchInfo[] arrSwitch = null;
        private ArrayList arrCon = null;
        private bool bClientInUSA = false;          //if it is usa client then true else false
        private string mSystemName = string.Empty;  //the name of system ,like 'ap','ar'

        private struct SwitchInfo
        {
            public bool IsLogic;
            public string Name;
            public string OldValue;
            public string NewValue;
            public string ValueType;
            public string ValueFormat;
            public int MaxLength;
            public string ValueCheck;
            public string SwitchHelp;
            public byte[] ValueStamp;
            public bool NeedPickUp;
            public int PickUpIdx;
            public string SwitchSys;
            //public bool NeedListBox;
            public bool NeedShowDate;
            public bool NeedValidCheck;
        }
        #endregion

        #region Constructor Functions
        private MenuInfo m_MenuInfo = new MenuInfo();
        public override MenuInfo CurrentMenuInfo
        {
            get
            {
                return m_MenuInfo;
            }
            set
            {
                m_MenuInfo = value;
                #region Load Control
                TabPage tbpCon = null;
                switch (this.m_MenuInfo.iParameter)
                {
                    case 1:
                        tbpCon = tbpOE;
                        break;
                    case 2:
                        tbpCon = tbpAP;
                        break;
                    case 3:
                        tbpCon = tbpAR;
                        break;
                    case 4:
                        tbpCon = tbpIM;
                        break;
                    case 5:
                        tbpCon = tbpPO;
                        break;
                    case 6:
                        tbpCon = tbpM;
                        break;
                    case 7:
                        tbpCon = tbpRM;
                        break;
                }
                //LoadAllControl(new ArrayList(tbcMain.Controls));
                //this.arraycontrols.Sort(new mySortControlByName());
                this.tbcMain.SelectedIndex = this.CurrentMenuInfo.iParameter - 1;
                this.tbcMain.Top = 27;
                this.Text = this.CurrentMenuInfo.strMenuName;
                this.Cursor = Cursors.WaitCursor;
                InitializeForm();
                this.Cursor = Cursors.Default;
                switch (this.m_MenuInfo.iParameter)
                {
                    case 1: //OE
                        break;
                    case 2: //AP
                        //this.tbcMain.Height = 290;
                        this.Height = 230;
                        break;
                    case 3: //AR
                        this.Height = 380;
                        break;
                    case 4: //IM
                        this.Height = 423;
                        break;
                    case 5: //PO
                        //this.Height = 423;
                        this.Height = 180;
                        this.Width = 480;
                        break;
                    case 6: //M
                        break;
                    case 7: //RM
                        this.Height = 223;
                        this.Width = 740;
                        break;
                }
                #endregion
            }
        }
        public frmMMiscKeyMtn()
        {
            InitializeComponent();
            LoadAllControl(new ArrayList(this.Controls));
            this.arraycontrols.Sort(new mySortControlByName());
            this.tbcMain.DrawMode = TabDrawMode.OwnerDrawFixed;
            this.tbcAR.DrawMode = TabDrawMode.OwnerDrawFixed;
            this.MinimumSize = this.Size;
        }
        #endregion

        #region ***Form Events
        private void frmMMiscKeyMtn_Load(object sender, EventArgs e)
        {
            #region Load Control
            //TabPage tbpCon = null;
            //switch (this.CurrentMenuInfo.iParameter)
            //{
            //    case 1:
            //        tbpCon = tbpOE;
            //        break;
            //    case 2:
            //        tbpCon = tbpAP;
            //        break;
            //    case 3:
            //        tbpCon = tbpAR;
            //        break;
            //    case 4:
            //        tbpCon = tbpIM;
            //        break;
            //    case 5:
            //        tbpCon = tbpPO;
            //        break;
            //    case 6:
            //        tbpCon = tbpM;
            //        break;
            //    case 7:
            //        tbpCon = tbpRM;
            //        break;
            //}
            //LoadAllControl(new ArrayList(tbpCon.Controls));
            //this.arraycontrols.Sort(new mySortControlByName());
            #endregion

            //this.tbcMain.SelectedIndex = this.CurrentMenuInfo.iParameter - 1;
            //this.tbcMain.Top = -25;
            //this.Text = this.CurrentMenuInfo.strMenuName;
            //this.Cursor = Cursors.WaitCursor;
            //InitializeForm();
            //this.Cursor = Cursors.Default;

            //switch (this.CurrentMenuInfo.iParameter)
            //{
            //    case 1: //OE
            //        break;
            //    case 2: //AP
            //        //this.tbcMain.Height = 290;
            //        this.Height = 230;
            //        break;
            //    case 3: //AR
            //        this.Height = 380;
            //        break;
            //    case 4: //IM
            //        this.Height = 423;
            //        break;
            //    case 5: //PO
            //        //this.Height = 423;
            //        this.Height = 180;
            //        this.Width = 480;
            //        break;
            //    case 6: //M
            //        break;
            //    case 7: //RM
            //        this.Height = 223;
            //        this.Width = 740;
            //        break;
            //}
        }

        private void Field_TextChanged(object sender, EventArgs e)
        {
            Control con = null;
            Control conNext = null;
            Control conPrev = null;
            Control conNextNext = null;
            Control conPrevPrev = null;
            int iIndex = 0;
                
            con = sender as Control;
            if (con == null || arrCon == null) return;

            #region get index
            if (BaseFunctions.IsNumeric(con.Name.Substring(con.Name.Length - 2)))
                iIndex = CvtFunc.ToInt(con.Name.Substring(con.Name.Length - 2));
            else
                iIndex = CvtFunc.ToInt(con.Name.Substring(con.Name.Length - 1));
            #endregion

            arrSwitch[iIndex].NewValue = con.Text;

            switch (this.CurrentMenuInfo.iParameter)
            {
                case 1: //OE
                    switch (arrSwitch[iIndex].Name.ToUpper())
                    {
                        case "REMNO":
                            lblOeRemDesc0.Text = DataFunctions.GetFieldValue("oeRecurringRemark", "RemDesc", "RemNo='" + con.Text + "'");
                            break;
                        case "REMNO1":
                            lblOeRemDesc1.Text = DataFunctions.GetFieldValue("oeRecurringRemark", "RemDesc", "RemNo='" + con.Text + "'");
                            break;
                        case "REMNO2":
                            lblOeRemDesc2.Text = DataFunctions.GetFieldValue("oeRecurringRemark", "RemDesc", "RemNo='" + con.Text + "'");
                            break;
                    }
                    break;
                case 2: //AP

                    if (iIndex < arrCon.Count - 1) conNext = arrCon[iIndex + 1] as Control;
                    if (iIndex > 0) conPrev = arrCon[iIndex - 1] as Control;

                    switch (arrSwitch[iIndex].Name.ToUpper())
                    {
                        case "ACCRUALDIFFTACCTNO":
                             lblDesc0.Text = DataFunctions.GetFieldValue("glAccount", "AcctDesc", "AcctNo='" + con.Text + "' and ProfitNo='" + conNext.Text + "'").TrimEnd();
                            break;
                        case "ACCRUALDIFFPROFITNO":
                            lblDesc0.Text = DataFunctions.GetFieldValue("glAccount", "AcctDesc", "AcctNo='" + conPrev.Text + "' and ProfitNo='" + con.Text + "'").TrimEnd();
                            break;
                        case "GSTINPACCTNO":
                            lblDesc1.Text = DataFunctions.GetFieldValue("glAccount", "AcctDesc", "AcctNo='" + con.Text + "' and ProfitNo='" + conNext.Text + "'").TrimEnd();
                            break;
                        case "GSTINPPROFITNO":
                            lblDesc1.Text = DataFunctions.GetFieldValue("glAccount", "AcctDesc", "AcctNo='" + conPrev.Text + "' and ProfitNo='" + con.Text + "'").TrimEnd();
                            break;
                        case "QSTACCTNO":
                            lblDesc2.Text = DataFunctions.GetFieldValue("glAccount", "AcctDesc", "AcctNo='" + con.Text + "' and ProfitNo='" + conNext.Text + "'").TrimEnd();
                            break;
                        case "QSTPROFITNO":
                            lblDesc2.Text = DataFunctions.GetFieldValue("glAccount", "AcctDesc", "AcctNo='" + conPrev.Text + "' and ProfitNo='" + con.Text + "'").TrimEnd();
                            break;
                    }
                    break;
                case 3: //AR
                    if (iIndex < arrCon.Count - 1) conNext = arrCon[iIndex + 1] as Control;
                    if (iIndex > 0) conPrev = arrCon[iIndex - 1] as Control;
                    if (iIndex < arrCon.Count - 2) conNextNext = arrCon[iIndex + 2] as Control;
                    if (iIndex > 1) conPrevPrev = arrCon[iIndex - 2] as Control;
                    
                    switch (arrSwitch[iIndex].Name.ToUpper())
                    {
                        case "DFNSFACCOUNTNO":
                            lblArDesc0.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + con.Text + "' and ProfitNo='" + conNext.Text + "' and  BranchNo='" + conNextNext.Text + "'");
                            break;
                        case "DFNSFPROFITNO":
                            lblArDesc0.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + conPrev.Text + "' and ProfitNo='" + con.Text + "' and  BranchNo='" + conNext.Text + "'");
                            break;
                        case "DFNSFBRANCHNO":
                            lblArDesc0.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + conPrevPrev.Text + "' and ProfitNo='" + conPrev.Text + "' and  BranchNo='" + con.Text + "'");
                            break;
                    }
                    break;
                case 4: //IM
                    break;
                case 5: //PO
                    break;
                case 6: //M
                    break;
                case 7: //RM

                    if (iIndex < arrCon.Count - 1) conNext = arrCon[iIndex + 1] as Control;
                    if (iIndex > 0) conPrev = arrCon[iIndex - 1] as Control;
                    if (iIndex < arrCon.Count - 2) conNextNext = arrCon[iIndex + 2] as Control;
                    if (iIndex > 1) conPrevPrev = arrCon[iIndex - 2] as Control;

                    switch (arrSwitch[iIndex].Name.ToUpper())
                    {
                        case "PLACCTNO":
                            lblRmDesc0.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + con.Text + "' and ProfitNo='" + conNext.Text + "' and  BranchNo='" + conNextNext.Text + "'");
                            break;
                        case "PLPROFITNO":
                            lblRmDesc0.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + conPrev.Text + "' and ProfitNo='" + con.Text + "' and  BranchNo='" + conNext.Text + "'");
                            break;
                        case "PLBRANCHNO":
                            lblRmDesc0.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + conPrevPrev.Text + "' and ProfitNo='" + conPrev.Text + "' and  BranchNo='" + con.Text + "'");
                            break;
                        case "REMANLOCNO":
                            lblRmDesc1.Text = DataFunctions.GetFieldValue("mLocation", "LocationDesc", "LocationNo='" + con.Text + "'");
                            break;
                        case "REMANACCTNO":
                            lblRmDesc2.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + con.Text + "' and ProfitNo='" + conNext.Text + "'");
                            break;
                        case "REMANPROFITNO":
                            lblRmDesc2.Text = DataFunctions.GetFieldValue("glaccount", "AcctDesc", "AcctNo='" + conPrev.Text + "' and ProfitNo='" + con.Text + "'");
                            break;
                    }
                    break;
            }
        }

        private void Field_Leave(object sender, EventArgs e)
        {
            Control con = null;
            int iIndex = 0;
                
            con = sender as Control;
            if (con == null || arrCon == null) return;

            #region get index
            if (BaseFunctions.IsNumeric(con.Name.Substring(con.Name.Length - 2)))
                iIndex = CvtFunc.ToInt(con.Name.Substring(con.Name.Length - 2));
            else
                iIndex = CvtFunc.ToInt(con.Name.Substring(con.Name.Length - 1));
            #endregion

            con.Text = BaseFunctions.FormatField(con.Text, arrSwitch[iIndex].ValueFormat);

            if (arrSwitch[iIndex].ValueType != null && arrSwitch[iIndex].ValueType.Substring(0, 1) == "N" && arrSwitch[iIndex].ValueFormat == string.Empty)
                con.Text = CvtFunc.ToDouble(con.Text).ToString();

            arrSwitch[iIndex].NewValue = con.Text;

            switch (this.CurrentMenuInfo.iParameter)
            {
                case 1: //OE
                    break;
                case 2: //AP
                    break;
                case 3: //AR
                    break;
                case 4: //IM
                    break;
                case 5: //PO
                    break;
                case 6: //M
                    break;
                case 7: //RM
                    break;
            }
        }

        private void Field_Validating(object sender, CancelEventArgs e)
        {
            Control con = null;
            string strErrPrompt = string.Empty;
            int iIndex = 0;
            int iLookUpIndex = 0;

            con = sender as Control;
            if (con == null || arrCon == null || this.ActiveControl == null)
            {
                e.Cancel = false;
                return;
            }

            #region get index
            if (BaseFunctions.IsNumeric(con.Name.Substring(con.Name.Length - 2)))
                iIndex = CvtFunc.ToInt(con.Name.Substring(con.Name.Length - 2));
            else
                iIndex = CvtFunc.ToInt(con.Name.Substring(con.Name.Length - 1));

            if (BaseFunctions.IsNumeric(this.ActiveControl.Name.Substring(this.ActiveControl.Name.Length - 2)))
                iLookUpIndex = CvtFunc.ToInt(this.ActiveControl.Name.Substring(this.ActiveControl.Name.Length - 2));
            else
                iLookUpIndex = CvtFunc.ToInt(this.ActiveControl.Name.Substring(this.ActiveControl.Name.Length - 1));
            #endregion

            if ((iLookUpIndex == arrSwitch[iIndex].PickUpIdx && this.ActiveControl is ButtonEx) || this.ActiveControl.Name == "btnExit")
            {
                e.Cancel = false;
                this.errProvider.SetError(con, string.Empty);
                return;
            }

            if (!TextCheck(iIndex, ref strErrPrompt))
            {
                this.errProvider.SetError(con, strErrPrompt);
                if (strErrPrompt.Trim() != "") MsgBoxEx.Show(strErrPrompt,SysVar.WarnTitle);
                e.Cancel = true;
            }
            else
            {
                if (strErrPrompt.Trim() != "") MsgBoxEx.Show(strErrPrompt, SysVar.WarnTitle);
                this.errProvider.SetError(con, "");
            }
        }

        protected override void  ubtLookUp_Click(object sender, EventArgs e)
        {
            string strSql="", strFindValue="",strFieldName="";
            Control con = sender as Control;
            if (con == null) return;
            Control ocon = null;
            switch (con.Name)
            {
                #region OE
                case "ubtOe1":
                case "ubtOe2":
                case "ubtOe3":
                case "ubtOe4":
                case "ubtOe5":
                case "ubtOe6":
                    switch (con.Name)
                    {
                        case "ubtOe1":
                            strFindValue = txtOeFields3.Text;
                            break;
                        case "ubtOe2":
                            strFindValue = txtOeFields8.Text;
                            break;
                        case "ubtOe3":
                            strFindValue = txtOeFields13.Text;
                            break;
                        case "ubtOe4":
                            strFindValue = txtOeFields18.Text;
                            break;
                        case "ubtOe5":
                            strFindValue = txtOeFields22.Text;
                            break;
                        case "ubtOe6":
                            strFindValue = txtOeFields24.Text;
                            break;
                        default:
                            break;
                    }
                    strFieldName = "AcctNo";
                    strSql = BaseFunctions.GetLookUpSQL("glAccount");
                    switch (con.Name)
                    {
                        case "ubtOe1":
                            ocon = txtOeFields3;
                            break;
                        case "ubtOe2":
                            ocon = txtOeFields8;
                            break;
                        case "ubtOe3":
                            ocon = txtOeFields13;
                            break;
                        case "ubtOe4":
                            ocon = txtOeFields18;
                            break;
                        case "ubtOe5":
                            ocon = txtOeFields22;
                            break;
                        case "ubtOe6":
                            ocon = txtOeFields24;
                            break;
                        default:
                            break;
                    }
                    break;
                case "ubtOe7":
                case "ubtOe8":
                case "ubtOe9":
                case "ubtOe10":
                    switch (con.Name)
                    {
                        case "ubtOe7":
                            strFindValue = txtOeFields27.Text;
                            break;
                        case "ubtOe8":
                            strFindValue = txtOeFields28.Text;
                            break;
                        case "ubtOe9":
                            strFindValue = txtOeFields29.Text;
                            break;
                        case "ubtOe10":
                            strFindValue = txtOeFields30.Text;
                            break;
                        default:
                            break;
                    }
                    strFieldName = "AcctNo";
                    strSql = BaseFunctions.GetLookUpSQL("glAccount");
                    switch (con.Name)
                    {
                        case "ubtOe7":
                            ocon = txtOeFields27;
                            break;
                        case "ubtOe8":
                            ocon = txtOeFields28;
                            break;
                        case "ubtOe9":
                            ocon = txtOeFields29;
                            break;
                        case "ubtOe10":
                            ocon = txtOeFields30;
                            break;
                        default:
                            break;
                    }
                    break;
                case "ubtOe11":
                    strFindValue = txtOeFields38.Text;
                    strFieldName = "Unit";
                    strSql = "SELECT Unit,UnitDesc,Type FROM imUnit Order By Unit";
                    ocon = txtOeFields38;
                    break;
                case "ubtOe12":
                    strFindValue = txtOeFields42.Text;
                    strFieldName = "Description";
                    strSql = "SELECT FobNo,Description FROM mFob Order By FobNo";
                    ocon = txtOeFields42;
                    break;
                case "ubtOe13":
                    strFindValue = txtOeFields43.Text;
                    strFieldName = "ViaDesc";
                    strSql = "SELECT ViaNo,ViaDesc FROM arShipVia Order By ViaNo";
                    ocon = txtOeFields43;
                    break;
                case "ubtOe14":
                case "ubtOe15":
                case "ubtOe16":
                    strFindValue = (con.Name == ubtOe14.Name ? txtOeFields45.Text : (con.Name == ubtOe15.Name ? txtOeFields46.Text : txtOeFields47.Text));
                    strFieldName = "RemNo";
                    strSql = "SELECT RemNo,RemDesc FROM oeRecurringRemark Order By RemNo";
                    ocon = (con.Name == ubtOe14.Name ? txtOeFields45 : (con.Name == ubtOe15.Name ? txtOeFields46: txtOeFields47));
                    //strCaption = "Remark#"
                    break;
                case "ubtOe17":
                    strFindValue = txtOeFields48.Text;
                    strFieldName = "TermDesc";
                    strSql = "SELECT TermNo,TermDesc FROM arTerm Order By TermNo";
                    ocon = txtOeFields48;
                    //strCaption = "Terms";
                    break;
                #endregion
                #region AP
                case "ubtAp1" : //ap--G/L Account for Accrued Difference
                case "ubtAp2" : //ap--GST TaxCredit G/L Account Number
                case "ubtAp5": //ap--G/L Account for Freight Accrued Difference
                case "ubtAp6": //ap--QST G/L Account for 
                    strFindValue =con.Name == ubtAp6.Name ?txtApFields13.Text  :( con.Name == ubtAp5.Name ? txtApFields11.Text :(con.Name == ubtAp1.Name ? txtApFields4.Text : txtApFields7.Text));
                    strFieldName = "AcctNo";
                    strSql = "SELECT AcctNo, ProfitNo,AcctDesc as Description FROM glAccount Order By AcctNo";
                    ocon =con.Name == ubtAp5.Name ?txtApFields13 :( con.Name == ubtAp5.Name ? txtApFields11  : (con.Name == ubtAp1.Name ? txtApFields4 : txtApFields7));
                    break;
                case "ubtAp3" : //ap--Supplier Type for Inventory Supplier
                case "ubtAp4" : //Supplier Type for Trucking Firm
                    strFindValue = (con.Name == ubtAp3.Name ? txtApFields9.Text :  txtApFields10.Text);
                    strFieldName = "TypeNo";
                    strSql = "SELECT TypeNo, TypeDesc FROM apType Order By TypeNo";
                    ocon = (con.Name == ubtAp3.Name ? txtApFields9 : txtApFields10);
                    break;
                #endregion
                #region AR
                case "ubtAr1":
                    strFindValue = txtArFields7.Text;
                    strFieldName = "GroupNo";
                    strSql = "SELECT GroupNo,GroupDesc FROM arGroup Order By GroupNo";
                    ocon = txtArFields7;
                    break;
                case "ubtAr2":
                    strFindValue = txtArFields27.Text;
                    strFieldName = "AcctNo";
                    strSql = BaseFunctions.GetLookUpSQL("glAccount");
                    ocon = txtArFields27;
                    break;
                case "ubtRemitToNo":
                    strFindValue = txtArFields30.Text;
                    strFieldName = "RemitToNo";
                    strSql = "select RemitToNo,Street,City,ProvNo,PostalCode,CompanyName from mRemitTo order by RemitToNo ";
                    ocon = txtArFields30;
                    break;
                #endregion
                #region IM
                case "ubtIm1":
                    strFindValue = txtImFields18.Text;
                    strFieldName = "SupNo";
                    strSql = "SELECT SupNo,SupName FROM apSupplier Order By SupNo";
                    ocon = txtImFields18;
                    break;
                case "ubtIm2":
                    strFindValue = txtImFields19.Text;
                    strFieldName = "AcctNo";
                    strSql = "select AcctNo,ProfitNo,BranchNo from glAccount";
                    ocon = txtImFields19;
                    break;
                #endregion
                #region PO
                case "ubtPo1":
                    strFindValue = txtPoFields0.Text;
                    strSql = "SELECT FobNo,Description FROM mFob Order By FobNo";
                    strFieldName = "Description";
                    ocon = txtPoFields0;
                    //strCaption = "FOB"
                    break;
                case "ubtPo2":
                    strFindValue = txtPoFields1.Text;
                    strSql = "SELECT ViaNo,ViaDesc FROM arShipVia Order By ViaNo";
                    strFieldName = "ViaDesc";
                    ocon = txtPoFields1;
                    //strCaption = "ShipVia"
                    break;
                #endregion
                #region M
                case "ubtM1":
                    strFindValue = txtMFields23.Text;
                    strFieldName = "TaxCode";
                    strSql = "select recid, TaxCode, Description, TaxPct from mSalesTax";
                    ocon = txtMFields23;
                    break;
                #endregion
                #region RM
                case "ubtRm1":
                case "ubtRm3":
                    strFindValue = (con.Name == ubtRm1.Name ? txtRmFields0.Text : txtRmFields4.Text);
                    strFieldName = "AcctNo";
                    strSql = BaseFunctions.GetLookUpSQL("glAccount");
                    ocon = (con.Name == ubtRm1.Name ? txtRmFields0 : txtRmFields4);
                    break;
                case "ubtRm2":
                    strFindValue = txtRmFields3.Text;
                    strFieldName = "LocationNo";
                    strSql = "SELECT LocationNo,LocationDesc FROM mLocation Order By LocationNo";
                    ocon = txtRmFields3;
                    break;
                #endregion
            }
            if (mblnLookUpSortByDescription) strSql = DataFunctions.GetSqlByDescriptionSort(strSql);
            mblnLookUpSortByDescription = false;

            WP.Modules.frmLookUp frmlookup = new WP.Modules.frmLookUp(strSql, "", strFindValue, strFieldName);
            frmlookup.ShowDialog();
            if (frmlookup.HaveReturnValue)
            {
                if (con.Name == "ubtAp1")
                {
                    txtApFields4.Text = frmlookup.GetReturnValue("AcctNo");
                    txtApFields5.Text = frmlookup.GetReturnValue("ProfitNo");
                    lblDesc0.Text = frmlookup.GetReturnValue("AcctDesc");
                }
                else if (con.Name == "ubtAp5")
                {
                    txtApFields11.Text = frmlookup.GetReturnValue("AcctNo");
                    txtApFields12.Text = frmlookup.GetReturnValue("ProfitNo");
                    
                }
                else if (con.Name == "ubtAp6")
                {
                    txtApFields13.Text = frmlookup.GetReturnValue("AcctNo");
                    txtApFields14.Text = frmlookup.GetReturnValue("ProfitNo");
                    lblDesc2.Text = frmlookup.GetReturnValue("AcctDesc");

                }
                else if (con.Name == "ubtAp2")
                {
                    txtApFields7.Text = frmlookup.GetReturnValue("AcctNo");
                    txtApFields8.Text = frmlookup.GetReturnValue("ProfitNo");
                    lblDesc1.Text = frmlookup.GetReturnValue("AcctDesc");
                }
                else if (con.Name == "ubtAr2")
                {
                    txtArFields27.Text = frmlookup.GetReturnValue("AcctNo");
                    txtArFields28.Text = frmlookup.GetReturnValue("ProfitNo");
                    txtArFields29.Text = frmlookup.GetReturnValue("BranchNo");
                    lblArDesc0.Text = frmlookup.GetReturnValue("AcctDesc");
                }
                else if (con.Name == "ubtIm2")
                {
                    txtImFields19.Text = frmlookup.GetReturnValue("AcctNo");
                    txtImFields20.Text = frmlookup.GetReturnValue("ProfitNo");
                    txtImFields21.Text = frmlookup.GetReturnValue("BranchNo");
                }
                else if (con.Name == "ubtOe1")
                {
                    txtOeFields3.Text = frmlookup.GetReturnValue("AcctNo");
                    txtOeFields4.Text = frmlookup.GetReturnValue("ProfitNo");
                }
                else if (con.Name == "ubtOe2")
                {
                    txtOeFields8.Text = frmlookup.GetReturnValue("AcctNo");
                    txtOeFields9.Text = frmlookup.GetReturnValue("ProfitNo");
                }
                else if (con.Name == "ubtOe3")
                {
                    txtOeFields13.Text = frmlookup.GetReturnValue("AcctNo");
                    txtOeFields14.Text = frmlookup.GetReturnValue("ProfitNo");
                }
                else if (con.Name == "ubtOe4")
                {
                    txtOeFields18.Text = frmlookup.GetReturnValue("AcctNo");
                    txtOeFields19.Text = frmlookup.GetReturnValue("ProfitNo");
                }
                else if (con.Name == "ubtOe5")
                {
                    txtOeFields22.Text = frmlookup.GetReturnValue("AcctNo");
                    txtOeFields23.Text = frmlookup.GetReturnValue("ProfitNo");
                }
                else if (con.Name == "ubtOe6")
                {
                    txtOeFields24.Text = frmlookup.GetReturnValue("AcctNo");
                    txtOeFields25.Text = frmlookup.GetReturnValue("ProfitNo");
                }
                else if (con.Name == "ubtM1")
                {
                    txtMFields23.Text = frmlookup.GetReturnValue("TaxCode");
                    txtMFields26.Text = DataFunctions.GetFieldValue("mSalesTax", "ReversionNo", "RecID = '" + frmlookup.GetReturnValue("RecId") + "'");
                }
                else if (con.Name == "ubtRm1")
                {
                    txtRmFields0.Text = frmlookup.GetReturnValue("AcctNo");
                    txtRmFields1.Text = frmlookup.GetReturnValue("ProfitNo");
                    txtRmFields2.Text = frmlookup.GetReturnValue("BranchNo");
                }
                else if (con.Name == "ubtRm3")
                {
                    txtRmFields4.Text = frmlookup.GetReturnValue("AcctNo");
                    txtRmFields5.Text = frmlookup.GetReturnValue("ProfitNo");
                }
                else
                    ocon.Text = frmlookup.GetReturnValue(strFieldName);

                ocon.Focus();
            }
            frmlookup.Close();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {

            if (!ValidCheck()) return;
            if (SaveData())
                this.Close();
        }

        private void btnExit_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void frmMMiscKeyMtn_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Return) return;
            #region if Last field of the tabpage, set focus in Update button
            switch (this.CurrentMenuInfo.iParameter)
            {
                case 1: // OE
                    if (this.ActiveControl.Name == txtOeFields48.Name)
                    {
                        //this.btnUpdate.Focus();
                        e.SuppressKeyPress = true;
                    }
                    break;
                case 2: // AP
                    if (this.ActiveControl.Name == txtApFields10.Name)
                    {
                        //this.btnUpdate.Focus();
                        e.SuppressKeyPress = true;
                    }
                    break;
                case 3: // AR
                    if (this.ActiveControl.Name == txtArText0.Name && txtArText0.Lines.Length >= 2)
                    {
                        this.txtArText1.Focus();
                        e.SuppressKeyPress = true;
                    }
                    else if (this.ActiveControl.Name == txtArText1.Name && txtArText1.Lines.Length >= 2)
                    {
                        this.txtArText2.Focus();
                        e.SuppressKeyPress = true;
                    }
                    else if (this.ActiveControl.Name == txtArText2.Name && txtArText2.Lines.Length >= 4)
                    {
                        this.txtArFields23.Focus();
                        e.SuppressKeyPress = true;
                    }
                    break;
                case 4: // IM
                    if (this.ActiveControl.Name == txtImFields23.Name)
                    {
                        //this.btnUpdate.Focus();
                        e.SuppressKeyPress = true;
                    }
                    break;
                case 5: // PO
                    if (this.ActiveControl.Name == txtPoFields1.Name)
                    {
                        //this.btnUpdate.Focus();
                        e.SuppressKeyPress = true;
                    }
                    break;
                case 6: // M
                    if (this.ActiveControl.Name == txtMFields26.Name)
                    {
                        //this.btnUpdate.Focus();
                        e.SuppressKeyPress = true;
                    }
                    break;
            }
            #endregion
        }

        private void txtArText_TextChanged(object sender, System.EventArgs e)
        {
            int intLineCount = 0;
            string strText = string.Empty;
            
            TextBox txt = sender as TextBox;
            if (txt == null) return;

            intLineCount = txt.Lines.Length;
            if (txt.Name == txtArText0.Name)
            {
                if (intLineCount > 2)
                {
                    strText = txtArFields15.Text + "\r\n" + txtArFields16.Text;
                    txt.Text = strText;
                    txt.SelectionLength = txt.Text.Length;
                }
                if (txt.Lines.Length > 0)
                    txtArFields15.Text = txt.Lines.GetValue(0).ToString();
                else
                    txtArFields15.Text = string.Empty;
                if (txt.Lines.Length > 1)
                    txtArFields16.Text = txt.Lines.GetValue(1).ToString();
                else
                    txtArFields16.Text = string.Empty;
            }
            else if(txt.Name == txtArText1.Name)
            {
                if (intLineCount > 2)
                {
                    strText = txtArFields17.Text + "\r\n" + txtArFields18.Text;
                    txt.Text = strText;
                    txt.SelectionLength = txt.Text.Length;
                }
                if (txt.Lines.Length > 0)
                    txtArFields17.Text = txt.Lines.GetValue(0).ToString();
                else
                    txtArFields17.Text = string.Empty;
                if (txt.Lines.Length > 1)
                    txtArFields18.Text = txt.Lines.GetValue(1).ToString();
                else
                    txtArFields18.Text = string.Empty;
            }
            else if(txt.Name == txtArText2.Name)
            {
                if (intLineCount > 4)
                {
                    strText = txtArFields19.Text + "\r\n" + txtArFields20.Text + "\r\n" +
                              txtArFields21.Text + "\r\n" + txtArFields22.Text;
                    txt.Text = strText;
                    txt.SelectionLength = txt.Text.Length;
                }
                if (txt.Lines.Length > 0)
                    txtArFields19.Text = txt.Lines.GetValue(0).ToString();
                else
                    txtArFields19.Text = string.Empty;
                if (txt.Lines.Length > 1)
                    txtArFields20.Text = txt.Lines.GetValue(1).ToString();
                else
                    txtArFields20.Text = string.Empty;
                if (txt.Lines.Length > 2)
                    txtArFields21.Text = txt.Lines.GetValue(2).ToString();
                else
                    txtArFields21.Text = string.Empty;
                if (txt.Lines.Length > 3)
                    txtArFields22.Text = txt.Lines.GetValue(3).ToString();
                else
                    txtArFields22.Text = string.Empty;
            }
        }

        private void tbcMain_DrawItem(object sender, DrawItemEventArgs e)
        {
            BaseFunctions.TabControl_DrawItem(sender, e, true);
        }

        private void tbcAR_DrawItem(object sender, DrawItemEventArgs e)
        {
            BaseFunctions.TabControl_DrawItem(sender, e, true);
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            base.OnHelp();
        }

        #endregion

        #region ***Form Functions
        private void InitializeForm()
        {
            string strSwithValue = string.Empty;
            Control con = null;
            ComboBoxEx.ComboBoxExItem oitem = null;
            ComboBoxEx ucbCombox = null;
            int i = 0;

            InitArrControl();

            switch (this.CurrentMenuInfo.iParameter)
            {
                case 1:
                    #region OE
                    string strGstLabelValue = string.Empty;
                    string strPstLabelValue = string.Empty;
                    strGstLabelValue = DataFunctions.GetmMiscValue("GstLabel", "m");
                    strPstLabelValue = DataFunctions.GetmMiscValue("PstLabel", "m");

                    if (!DataFunctions.GetmSwitchValue("UsePctInOverdueLimit", "Oe")) //Use Amount
                        lblOeTitle33.Text = "Credit Approval Required Overdue Total Receivable Amount";
                    else //Use PCT
                        lblOeTitle33.Text = "Credit Approval Required Overdue Total Receivable Pct(%)";

                    lblOeTitle30.Text = (strGstLabelValue == ""? "GST": strGstLabelValue);
                    lblOeTitle26.Text = (strGstLabelValue == ""? "GST": strGstLabelValue);
                    lblOeTitle31.Text = (strPstLabelValue == ""? "PST": strPstLabelValue);
                    lblOeTitle28.Text = (strPstLabelValue == ""? "PST": strPstLabelValue);
                     
                    arrSwitch = new SwitchInfo[intOeSwitchNum];
           
                    arrSwitch[0].Name = "CustOrdLabel1";
                    arrSwitch[1].Name = "Fld1GstExempt";
                    arrSwitch[1].IsLogic = true;
                    arrSwitch[2].Name = "Fld1PSTExempt";
                    arrSwitch[2].IsLogic = true;
                    
                    arrSwitch[3].Name = "O1AcctNo";
                    arrSwitch[3].NeedPickUp = true;
                    arrSwitch[3].PickUpIdx = 1;
                    arrSwitch[3].NeedValidCheck = true;

                    arrSwitch[4].Name = "O1ProfitNo";
                    arrSwitch[4].NeedPickUp = true;
                    arrSwitch[4].PickUpIdx = 1;
                    arrSwitch[4].NeedValidCheck = true;

                    arrSwitch[5].Name = "CustOrdLabel2";
                    arrSwitch[6].Name = "Fld2GstExempt";
                    arrSwitch[6].IsLogic = true;
                    arrSwitch[7].Name = "Fld2PSTExempt";
                    arrSwitch[7].IsLogic = true;

                    arrSwitch[8].Name = "O2AcctNo";
                    arrSwitch[8].NeedPickUp = true;
                    arrSwitch[8].PickUpIdx = 2;
                    arrSwitch[8].NeedValidCheck = true;

                    arrSwitch[9].Name = "O2ProfitNo";
                    arrSwitch[9].NeedPickUp = true;
                    arrSwitch[9].PickUpIdx = 2;
                    arrSwitch[9].NeedValidCheck = true;

                    arrSwitch[10].Name = "CustOrdLabel3";
                    arrSwitch[11].Name = "Fld3GstExempt";
                    arrSwitch[11].IsLogic = true;
                    arrSwitch[12].Name = "Fld3PSTExempt";
                    arrSwitch[12].IsLogic = true;
                    
                    arrSwitch[13].Name = "O3AcctNo";
                    arrSwitch[13].NeedPickUp = true;
                    arrSwitch[13].PickUpIdx = 3;
                    arrSwitch[13].NeedValidCheck = true;
                    
                    arrSwitch[14].Name = "O3ProfitNo";
                    arrSwitch[14].NeedPickUp = true;
                    arrSwitch[14].PickUpIdx = 3;
                    arrSwitch[14].NeedValidCheck = true;

                    arrSwitch[15].Name = "CustOrdLabel4";
                    arrSwitch[16].Name = "Fld4GstExempt";
                    arrSwitch[16].IsLogic = true;
                    arrSwitch[17].Name = "Fld4PSTExempt";
                    arrSwitch[17].IsLogic = true;
                    
                    arrSwitch[18].Name = "O4AcctNo";
                    arrSwitch[18].NeedPickUp = true;
                    arrSwitch[18].PickUpIdx = 4;
                    arrSwitch[18].NeedValidCheck = true;

                    arrSwitch[19].Name = "O4ProfitNo";
                    arrSwitch[19].NeedPickUp = true;
                    arrSwitch[19].PickUpIdx = 4;
                    arrSwitch[19].NeedValidCheck = true;
                    
                    arrSwitch[20].Name = "MaxGMPct";
                    arrSwitch[21].Name = "MinGMPct";

                    arrSwitch[22].Name = "GstAcctNo";
                    arrSwitch[22].NeedPickUp = true;
                    arrSwitch[22].PickUpIdx = 5;
                    arrSwitch[22].NeedValidCheck = true;

                    arrSwitch[23].Name = "GstProfitNo";
                    arrSwitch[23].NeedPickUp = true;
                    arrSwitch[23].PickUpIdx = 5;
                    arrSwitch[23].NeedValidCheck = true;

                    arrSwitch[24].Name = "PstAcctNo";
                    arrSwitch[24].NeedPickUp = true;
                    arrSwitch[24].PickUpIdx = 6;
                    arrSwitch[24].NeedValidCheck = true;

                    arrSwitch[25].Name = "PstProfitNo";
                    arrSwitch[25].NeedPickUp = true;
                    arrSwitch[25].PickUpIdx = 6;
                    arrSwitch[25].NeedValidCheck = true;

                    arrSwitch[26].Name = "UseSlspPCNo";
                    arrSwitch[26].IsLogic = true;

                    arrSwitch[27].Name = "SlspStAcctNo1";
                    arrSwitch[27].NeedPickUp = true;
                    arrSwitch[27].PickUpIdx = 7;
                    arrSwitch[27].NeedValidCheck = true;

                    arrSwitch[28].Name = "SlspEnAcctNo1";
                    arrSwitch[28].NeedPickUp = true;
                    arrSwitch[28].PickUpIdx = 8;
                    arrSwitch[28].NeedValidCheck = true;

                    arrSwitch[29].Name = "SlspStAcctNo2";
                    arrSwitch[29].NeedPickUp = true;
                    arrSwitch[29].PickUpIdx = 9;
                    arrSwitch[29].NeedValidCheck = true;

                    arrSwitch[30].Name = "SlspEnAcctNo2";
                    arrSwitch[30].NeedPickUp = true;
                    arrSwitch[30].PickUpIdx = 10;
                    arrSwitch[30].NeedValidCheck = true;

                    arrSwitch[31].Name = "SlspStAcctNo3";
                    arrSwitch[31].NeedPickUp = true;
                    arrSwitch[31].PickUpIdx = 31;
                    arrSwitch[31].NeedValidCheck = true;

                    arrSwitch[32].Name = "SlspEnAcctNo3";
                    arrSwitch[32].NeedPickUp = true;
                    arrSwitch[32].PickUpIdx = 32;
                    arrSwitch[32].NeedValidCheck = true;

                    arrSwitch[33].Name = "SlspStAcctNo4";
                    arrSwitch[33].NeedPickUp = true;
                    arrSwitch[33].PickUpIdx = 33;
                    arrSwitch[33].NeedValidCheck = true;

                    arrSwitch[34].Name = "SlspEnAcctNo4";
                    arrSwitch[34].NeedPickUp = true;
                    arrSwitch[34].PickUpIdx = 34;
                    arrSwitch[34].NeedValidCheck = true;

                    arrSwitch[35].Name = "SlspStAcctNo5";
                    arrSwitch[35].NeedPickUp = true;
                    arrSwitch[35].PickUpIdx = 35;
                    arrSwitch[35].NeedValidCheck = true;

                    arrSwitch[36].Name = "SlspEnAcctNo5";
                    arrSwitch[36].NeedPickUp = true;
                    arrSwitch[36].PickUpIdx = 36;
                    arrSwitch[36].NeedValidCheck = true;

                    arrSwitch[37].Name = "DfltFrtPrepaid";
                    //arrSwitch[37].NeedListBox = true;
                    ucbCombox = arrCon[37] as ComboBoxEx;
                    ucbCombox.ColumnNum = 2;
                    ucbCombox.Items.Clear();
                    oitem = new ComboBoxEx.ComboBoxExItem("Y", "Yes", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("N", "No", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("P", "Prepaid & Collect from customer", "", "");
                    ucbCombox.Items.Add(oitem);
                    ucbCombox.ColumnWidth = "21;140";

                    arrSwitch[38].Name = "DfltWtUnit";
                    arrSwitch[38].NeedPickUp = true;
                    arrSwitch[38].PickUpIdx = 11;
                    arrSwitch[38].NeedValidCheck = true;

                    arrSwitch[39].Name = "OverCrLimitAct";
                    //arrSwitch[39].NeedListBox = true;
                    ucbCombox = arrCon[39] as ComboBoxEx;
                    ucbCombox.ColumnNum = 2;
                    ucbCombox.Items.Clear();
                    oitem = new ComboBoxEx.ComboBoxExItem("1", "Put customer on credit hold", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("2", "Put sales order on credit hold status", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("3", "Put both customer and sales order on credit hold", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("4", "Over credit limit warning only", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("5", "No action (No warning)", "", "");
                    ucbCombox.Items.Add(oitem);
                    ucbCombox.ColumnWidth = "21;220";

                    arrSwitch[40].Name = "CrApprovalArGraceDay";
                    arrSwitch[40].NeedValidCheck = true;
                    
                    arrSwitch[41].Name = "CrApprovalTotArAmtLate";
                    arrSwitch[41].NeedValidCheck = true;
                    
                    arrSwitch[42].Name = "DefaultFOB";
                    arrSwitch[42].NeedPickUp = true;
                    arrSwitch[42].PickUpIdx = 12;
                    arrSwitch[42].NeedValidCheck = true;

                    arrSwitch[43].Name = "DefaultShipVia";
                    arrSwitch[43].NeedPickUp = true;
                    arrSwitch[43].PickUpIdx = 13;
                    arrSwitch[43].NeedValidCheck = true;

                    arrSwitch[44].Name = "MinGrossMarginAmt";
                    
                    for (i = 45; i<=47; i++)
                    {
                        arrSwitch[i].Name = "RemNo" + (i == 45? "": CvtFunc.ToString(i - 45));
                        arrSwitch[i].NeedPickUp = true;
                        arrSwitch[i].PickUpIdx = i - 31;
                        arrSwitch[i].NeedValidCheck = true;
                    }

                    arrSwitch[48].Name = "DftTsoSalesTerms";
                    arrSwitch[48].NeedPickUp = true;
                    arrSwitch[48].PickUpIdx = 17;
                    arrSwitch[48].NeedValidCheck = true;

                    arrSwitch[49].Name = "DefQuoExpiration";

                    arrSwitch[50].Name = "EstFreightCostPerMile";
                    arrSwitch[51].Name = "DesireGMforEachRoute";

                    arrSwitch[52].Name = "dftBottleLinesinDotMatrix";
                    arrSwitch[52].NeedPickUp = true;
                    arrSwitch[52].PickUpIdx = 13;
                    arrSwitch[52].NeedValidCheck = true;


                    for (i = 0; i<intOeSwitchNum; i++)
                    {
                        arrSwitch[i].SwitchSys = mSystemName;
                        if (!arrSwitch[i].NeedPickUp) arrSwitch[i].PickUpIdx = -1;
                        GetSwitchInfo(i);
                        con = arrCon[i] as Control;
                        if (con != null)
                        {
                            con.Text = arrSwitch[i].OldValue;
                        }
                    }

                    
                    break;
                    #endregion
                case 2:
                    #region AP
                    arrSwitch = new SwitchInfo[intApSwitchNum];

                    arrSwitch[0].Name = "Aging1";
                    arrSwitch[0].NeedValidCheck = true;
                    arrSwitch[1].Name = "Aging2";
                    arrSwitch[1].NeedValidCheck = true;
                    arrSwitch[2].Name = "Aging3";
                    arrSwitch[2].NeedValidCheck = true;
                    arrSwitch[3].Name = "Aging4";
                    arrSwitch[3].NeedValidCheck = true;

                    arrSwitch[4].Name = "AccrualDifftAcctNo";
                    arrSwitch[4].NeedValidCheck = true;
                    arrSwitch[4].NeedPickUp = true;
                    arrSwitch[4].PickUpIdx = 1;

                    arrSwitch[5].Name = "AccrualDIffProfitNo";
                    arrSwitch[5].NeedValidCheck = true;
                    arrSwitch[5].NeedPickUp = true;
                    arrSwitch[5].PickUpIdx = 1;

                    arrSwitch[6].Name = "AccrualDiff";
                    arrSwitch[7].Name = "GstInpAcctNo";
                    arrSwitch[7].NeedValidCheck = true;
                    arrSwitch[7].NeedPickUp = true;
                    arrSwitch[7].PickUpIdx = 2;
                    
                    arrSwitch[8].Name = "GstInpProfitno";
                    arrSwitch[8].NeedValidCheck = true;
                    arrSwitch[8].NeedPickUp = true;
                    arrSwitch[8].PickUpIdx = 2;

                    arrSwitch[9].Name = "LumberSupplierType";
                    arrSwitch[9].NeedValidCheck = true;
                    arrSwitch[9].NeedPickUp = true;
                    arrSwitch[9].PickUpIdx = 3;

                    arrSwitch[10].Name = "TruckingFirmType";
                    arrSwitch[10].NeedValidCheck = true;
                    arrSwitch[10].NeedPickUp = true;
                    arrSwitch[10].PickUpIdx = 4;

                    arrSwitch[11].Name = "FreightAccrualDifftAcctNo";
                    arrSwitch[11].NeedValidCheck = true;
                    arrSwitch[11].NeedPickUp = true;
                    arrSwitch[11].PickUpIdx = 5;

                    arrSwitch[12].Name = "FreightAccrualDIffProfitNo";
                    arrSwitch[12].NeedValidCheck = true;
                    arrSwitch[12].NeedPickUp = true;
                    arrSwitch[12].PickUpIdx = 5;

                    arrSwitch[13].Name = "QstAcctNo";
                    arrSwitch[13].NeedValidCheck = true;
                    arrSwitch[13].NeedPickUp = true;
                    arrSwitch[13].PickUpIdx = 6;

                    arrSwitch[14].Name = "QstProfitNo";
                    arrSwitch[14].NeedValidCheck = true;
                    arrSwitch[14].NeedPickUp = true;
                    arrSwitch[14].PickUpIdx = 6;

                    for (i = 0; i<intApSwitchNum; i++)
                    {
                        arrSwitch[i].SwitchSys = mSystemName;
                        if (!arrSwitch[i].NeedPickUp) arrSwitch[i].PickUpIdx = -1;
                        GetSwitchInfo(i);
                        con = arrCon[i] as Control;
                        if (con != null)
                        {
                            con.Text = arrSwitch[i].OldValue;
                        }
                    }
                    
                    bClientInUSA = DataFunctions.GetmSwitchValue("ClientInUSA", "M");
                    
                    if (bClientInUSA)
                    {
                        lblApTitle7.Visible = false;
                        con = arrCon[7] as Control;
                        con.Visible = false;
                        con = arrCon[8] as Control;
                        con.Visible = false;
                        ubtAp2.Visible = false;
                        lblDesc1.Visible = false;
                        lblApTitle8.Visible = false;
                    }
           
                    strSwithValue = DataFunctions.GetmMiscValue("GstLabel ", "m");
                    if (strSwithValue != string.Empty)
                    {
                        lblApTitle7.Text = strSwithValue + " " + "TaxCredit G/L Account Number :";
                        con = arrCon[7] as Control;
                        lblApTitle7.Left = con.Left - lblApTitle7.Width;
                    }
                    break;
                    #endregion
                case 3:
                    #region AR
                    tbcAR.SelectedIndex = 0;
                    arrSwitch = new SwitchInfo[intArSwitchNum];
                    arrSwitch[0].Name = "AgeingDay01"; 
                    arrSwitch[0].NeedValidCheck = true;
                    arrSwitch[1].Name = "AgeingDay02";
                    arrSwitch[1].NeedValidCheck = true;
                    arrSwitch[2].Name = "AgeingDay03";
                    arrSwitch[2].NeedValidCheck = true;
                    arrSwitch[3].Name = "AgeingDay04";
                    arrSwitch[3].NeedValidCheck = true;

                    arrSwitch[4].Name = "SlsAnalBaseDate";
                    //arrSwitch[4].NeedListBox = true;
                    ucbCombox = arrCon[4] as ComboBoxEx;
                    ucbCombox.ColumnNum = 2;
                    ucbCombox.Items.Clear();
                    oitem = new ComboBoxEx.ComboBoxExItem("1", "Invoice Date", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("2", "Post Date", "", "");
                    ucbCombox.Items.Add(oitem);

                    arrSwitch[5].Name = "SalesOrderDflt";
                    //arrSwitch[5].NeedListBox = true;
                    ucbCombox = arrCon[5] as ComboBoxEx;
                    ucbCombox.ColumnNum = 2;
                    ucbCombox.Items.Clear();
                    oitem = new ComboBoxEx.ComboBoxExItem("1", "acct", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("2", "cash", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("3", "cod", "", "");
                    ucbCombox.Items.Add(oitem);

                    arrSwitch[6].Name = "DfltInvSendType";
                    //arrSwitch[6].NeedListBox = true;
                    ucbCombox = arrCon[6] as ComboBoxEx;
                    ucbCombox.ColumnNum = 2;
                    ucbCombox.Items.Clear();
                    oitem = new ComboBoxEx.ComboBoxExItem("F", "(F)ax", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("M", "(M)ail", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("B", "(B)oth", "", "");
                    ucbCombox.Items.Add(oitem);

                    arrSwitch[7].Name = "DfltCustGroupNo";
                    arrSwitch[7].NeedValidCheck = true;
                    arrSwitch[7].NeedPickUp = true;
                    arrSwitch[7].PickUpIdx = 1;

                    arrSwitch[8].Name = "AnnualInvRate";
                    arrSwitch[9].Name = "AnnualInterestRate";
                    arrSwitch[10].Name = "MinInterestAmt";
                    arrSwitch[11].Name = "arOverDueDaysToTrdChrgInt";
                    arrSwitch[12].Name = "InterestRateToCust";
                    arrSwitch[13].Name = "MinInterestAmtToCust";
                    arrSwitch[14].Name = "arOverDueDaysToCustChrgInt";
                    arrSwitch[15].Name = "InterestMsg1";
                    arrSwitch[16].Name = "InterestMsg2";
                    arrSwitch[17].Name = "SpecialMsg1";
                    arrSwitch[18].Name = "SpecialMsg2";
                    arrSwitch[19].Name = "arStmtOver01";
                    arrSwitch[20].Name = "arStmtOver02";
                    arrSwitch[21].Name = "arStmtOver03";
                    arrSwitch[22].Name = "arStmtOver04";
                    arrSwitch[23].Name = "CreditRatingDesc01";
                    arrSwitch[24].Name = "CreditRatingDesc02";
                    arrSwitch[25].Name = "GraceDaysCustInvDisc";

                    arrSwitch[26].Name = "PostNetToAR";
                    arrSwitch[26].IsLogic = true;
                    //arrSwitch[26].NeedListBox = true;
                    ucbCombox = arrCon[26] as ComboBoxEx;
                    ucbCombox.ColumnNum = 2;
                    ucbCombox.Items.Clear();
                    oitem = new ComboBoxEx.ComboBoxExItem("Yes", "Invoice Amount in Receivable is Net of Customer Discount", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("No", "Invoice Amount in Receivable is the Gross Amount with Discount Allowed Amount", "", "");
                    ucbCombox.Items.Add(oitem);

                    arrSwitch[27].Name = "DfNSFAccountNo";
                    arrSwitch[27].NeedPickUp = true;
                    arrSwitch[27].PickUpIdx = 1;

                    arrSwitch[28].Name = "DfNSFProfitNo";
                    arrSwitch[28].NeedPickUp = true;
                    arrSwitch[28].PickUpIdx = 1;

                    arrSwitch[29].Name = "DfNSFBranchNo";
                    arrSwitch[29].NeedPickUp = true;
                    arrSwitch[29].PickUpIdx = 1;

                    arrSwitch[30].Name = "RemitToNo";
                    arrSwitch[30].NeedValidCheck = true;

                    for (i = 0; i<intArSwitchNum; i++)
                    {
                        arrSwitch[i].SwitchSys = mSystemName;
                        if (!arrSwitch[i].NeedPickUp) arrSwitch[i].PickUpIdx = -1;
                        GetSwitchInfo(i);
                        con = arrCon[i] as Control;
                        if (con != null)
                        {
                            con.Text = arrSwitch[i].OldValue;
                        }
                    }

                    txtArText0.Text = (arrSwitch[15].OldValue == string.Empty && arrSwitch[16].OldValue == string.Empty? string.Empty : arrSwitch[15].OldValue + "\r\n" + arrSwitch[16].OldValue);
                    txtArText1.Text = (arrSwitch[17].OldValue == string.Empty && arrSwitch[18].OldValue == string.Empty? string.Empty : arrSwitch[17].OldValue + "\r\n" + arrSwitch[18].OldValue);
                    txtArText2.Text = (arrSwitch[19].OldValue == string.Empty && arrSwitch[20].OldValue == string.Empty && arrSwitch[21].OldValue == string.Empty && arrSwitch[22].OldValue == string.Empty? string.Empty : arrSwitch[19].OldValue + "\r\n" + arrSwitch[20].OldValue + "\r\n" + arrSwitch[21].OldValue + "\r\n" + arrSwitch[22].OldValue);
                    
                    string strTraderPrompt = string.Empty;
                    strTraderPrompt = SysVar.TraderPrompt;
                    if (strTraderPrompt != "")
                    {
                        lblArTitle19.Text = "Annual Rate for Inventory Charges to " + strTraderPrompt + ":";
                        lblArTitle20.Text = "Annual Rate for Interest Charges to " + strTraderPrompt + ":";
                        lblArTitle21.Text = "Minimum Amt for Interest Charges to " + strTraderPrompt + ":";
                        lblArTitle22.Text = "Overdue Days Before Charge Interest To " + strTraderPrompt + ":";
                    }
                    break;
                    #endregion
                case 4:
                    #region IM
                    arrSwitch = new SwitchInfo[intImSwitchNum];
                    arrSwitch[0].Name = "NumberOfPrices";
                    arrSwitch[0].NeedValidCheck = true;
                    arrSwitch[1].Name = "Price1label";
                    arrSwitch[2].Name = "Price2label";
                    arrSwitch[3].Name = "Price3label";
                    arrSwitch[4].Name = "Price4label";
                    arrSwitch[5].Name = "Price5label";
                    arrSwitch[6].Name = "Price6label";
                    arrSwitch[7].Name = "Price7label";
                    arrSwitch[8].Name = "Price8label";
                    arrSwitch[9].Name = "Price9label";
                    arrSwitch[10].Name = "Price10label";
                    arrSwitch[11].Name = "WtAvgCostLabel";
                    arrSwitch[12].Name = "MarketCostLabel";
                    arrSwitch[13].Name = "EfftWtAvgCostLabel";
                    arrSwitch[14].Name = "ProdCatgLevel";
                    arrSwitch[14].NeedValidCheck = true;
                    arrSwitch[15].Name = "NumOfDecimalQty";
                    arrSwitch[16].Name = "NumOfDecimalPrice";
                    arrSwitch[17].Name = "CostMethod";
                    ucbCombox = arrCon[17] as ComboBoxEx;
                    ucbCombox.ColumnNum = 2;
                    ucbCombox.Items.Clear();
                    oitem = new ComboBoxEx.ComboBoxExItem("WA", "Weight Average Cost", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("AC", "Actual(by Lot/Tag) Cost", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("SC", "Standard Cost", "", "");
                    ucbCombox.Items.Add(oitem);
                    oitem = new ComboBoxEx.ComboBoxExItem("MK", "Market Cost", "", "");
                    ucbCombox.Items.Add(oitem);

                    arrSwitch[18].Name = "TreatmentSupNo";
                    arrSwitch[18].NeedPickUp = true;
                    arrSwitch[18].PickUpIdx = 1;
                    arrSwitch[18].NeedValidCheck = true;

                    arrSwitch[19].Name = "TreatmentAcctNo";
                    arrSwitch[19].NeedPickUp = true;
                    arrSwitch[19].PickUpIdx = 2;
                    arrSwitch[19].NeedValidCheck = true;

                    arrSwitch[20].Name = "TreatmentProfitNo";
                    arrSwitch[20].NeedPickUp = true;
                    arrSwitch[20].PickUpIdx = 2;
                    arrSwitch[20].NeedValidCheck = true;

                    arrSwitch[21].Name = "TreatmentBranchNo";
                    arrSwitch[21].NeedPickUp = true;
                    arrSwitch[21].PickUpIdx = 2;
                    arrSwitch[21].NeedValidCheck = true;

                    arrSwitch[22].Name = "PriceScale";
                    arrSwitch[23].Name = "CostScale";


                    
                    for (i = 0; i<intImSwitchNum; i++)
                    {
                        arrSwitch[i].SwitchSys = mSystemName;
                        if (!arrSwitch[i].NeedPickUp) arrSwitch[i].PickUpIdx = -1;
                        GetSwitchInfo(i);
                        con = arrCon[i] as Control;
                        if (con != null)
                        {
                            con.Text = arrSwitch[i].OldValue;
                        }
                    }
                    break;
                    #endregion
                case 5:
                    #region PO
                    arrSwitch = new SwitchInfo[intPoSwitchNum];
                    arrSwitch[0].Name = "DefaultFOB";
                    arrSwitch[1].Name = "DefaultShipVia";
                    for (i = 0; i<intPoSwitchNum; i++)
                    {
                        arrSwitch[i].SwitchSys = mSystemName;
                        arrSwitch[i].NeedPickUp = true;
                        arrSwitch[i].PickUpIdx = i + 1;
                        arrSwitch[i].NeedValidCheck = true;
                        GetSwitchInfo(i);
                        con = arrCon[i] as Control;
                        if (con != null)
                        {
                            con.Text = arrSwitch[i].OldValue;
                        }
                    }
                    break;
                    #endregion
                case 6:
                    #region MF
                    arrSwitch = new SwitchInfo[intMSwitchNum];
                    arrSwitch[0].Name = "CompanyName";
                    arrSwitch[1].Name = "Address1";
                    arrSwitch[2].Name = "Address2";
                    arrSwitch[3].Name = "Address3";
                    arrSwitch[4].Name = "Address4";
                    arrSwitch[5].Name = "CompanyEmail";
                    arrSwitch[6].Name = "CompanyWebSite";
                    arrSwitch[7].Name = "CompanyPhone";
                    arrSwitch[8].Name = "CompanyPhone01";
                    arrSwitch[9].Name = "CompanyPhone02";
                    arrSwitch[10].Name = "CompanyFax";
                    
                    arrSwitch[11].Name = "B_Address1";
                    arrSwitch[12].Name = "B_Address2";
                    arrSwitch[13].Name = "B_Address3";
                    arrSwitch[14].Name = "B_Address4";
                    arrSwitch[15].Name = "B_CompanyPhone01";
                    arrSwitch[16].Name = "B_CompanyPhone02";
                    arrSwitch[17].Name = "B_CompanyPhone03";
                    arrSwitch[18].Name = "B_CompanyFax";
                    arrSwitch[19].Name = "UPC";
                    arrSwitch[20].Name = "GstLabel";
                    arrSwitch[21].Name = "PstLabel";
                    arrSwitch[22].Name = "GstNum";
                    arrSwitch[23].Name = "PstNum";
                    arrSwitch[23].NeedPickUp = true;
                    arrSwitch[23].PickUpIdx = 1;

                    arrSwitch[24].Name = "GstPct";
                    arrSwitch[25].Name = "EDIIdNo";
                    arrSwitch[26].Name = "TaxReversionNo";

                    arrSwitch[27].Name = "FSCNumber";
                    for (i = 0; i<intMSwitchNum; i++)
                    {
                        arrSwitch[i].SwitchSys = mSystemName;
                        arrSwitch[i].NeedValidCheck = true;
                        if (!arrSwitch[i].NeedPickUp) arrSwitch[i].PickUpIdx = -1;
                        GetSwitchInfo(i);
                        con = arrCon[i] as Control;
                        if (con != null)
                        {
                            con.Text = arrSwitch[i].OldValue;
                        }
                    }
                    ////LoadPic 'load picture
                    
                    bClientInUSA = DataFunctions.GetmSwitchValue("ClientInUSA", "M");
                    
                    if (bClientInUSA)
                        gpbM3.Visible = false;

                    ////LoadPic
                    break;
                    #endregion
                case 7:
                    #region RM
                    arrSwitch = new SwitchInfo[intRmSwitchNum];
                    arrSwitch[0].Name = "PLAcctNo";
                    arrSwitch[0].NeedPickUp = true;
                    arrSwitch[0].PickUpIdx = 1;

                    arrSwitch[1].Name = "PLProfitNo";
                    arrSwitch[1].NeedPickUp = true;
                    arrSwitch[1].PickUpIdx = 1;

                    arrSwitch[2].Name = "PLBranchNo";
                    arrSwitch[2].NeedPickUp = true;
                    arrSwitch[2].PickUpIdx = 1;

                    arrSwitch[3].Name = "RemanLocNo";
                    arrSwitch[3].NeedPickUp = true;
                    arrSwitch[3].PickUpIdx = 2;

                    arrSwitch[4].Name = "RemanAcctNo";
                    arrSwitch[4].NeedPickUp = true;
                    arrSwitch[4].PickUpIdx = 3;

                    arrSwitch[5].Name = "RemanProfitNo";
                    arrSwitch[5].NeedPickUp = true;
                    arrSwitch[5].PickUpIdx = 3;

                    arrSwitch[6].Name = "MaxProfitLossAmt";
                    arrSwitch[6].NeedPickUp = false;
                    arrSwitch[6].PickUpIdx = -1;

                    for (i = 0; i<intRmSwitchNum; i++)
                    {
                        arrSwitch[i].SwitchSys = mSystemName;
                        arrSwitch[i].NeedValidCheck = true;
                        if (!arrSwitch[i].NeedPickUp) arrSwitch[i].PickUpIdx = -1;
                        GetSwitchInfo(i);
                        con = arrCon[i] as Control;
                        if (con != null)
                        {
                            con.Text = arrSwitch[i].OldValue;
                        }
                    }
                    break;
                    #endregion
            }
        }

        private bool SaveData()
        {
            string strSql = string.Empty;
            string strValue = string.Empty;
            string strType = string.Empty;
            int intMaxLen = 0;
            string strCheck = string.Empty;
            string strFieldType = string.Empty;
            int i = 0;
            bool bNeedCheck = false;
            byte[] btStamp = new byte[8];
            bool blnLogicSwitch = false;
            DBAccess dBAccess = new DBAccess(false,false);

            //if check pass then write data to database
            for (i = 0; i< arrSwitch.Length; i++)
            {
                if (arrSwitch[i].OldValue != arrSwitch[i].NewValue) //if switch value change
                {
                    btStamp = GetSwitchStamp(arrSwitch[i].Name, arrSwitch[i].SwitchSys, arrSwitch[i].IsLogic);
                    if (CnvStampToStr(btStamp,".") != CnvStampToStr(arrSwitch[i].ValueStamp,"."))
                    {
                        MsgBoxEx.Show(DataFunctions.GetMsg(this.Name, "MSG_UpdateFailed"), SysVar.WarnTitle);
                        return false;
                    }

                    blnLogicSwitch = arrSwitch[i].IsLogic;

                    if (!blnLogicSwitch) //miscSwitch
                    {
                        strValue = arrSwitch[i].NewValue;
                        strType = arrSwitch[i].ValueType;
                        intMaxLen = arrSwitch[i].MaxLength;
                        strCheck = arrSwitch[i].ValueCheck;
                        #region 1--check type
                        if (strType.ToUpper() == "Date".ToUpper())
                        {
                            strFieldType = "D";
                            if (strValue.Trim() != "" && !BaseFunctions.IsDate(strValue))
                            {
                                MsgBoxEx.Show(DataFunctions.GetMsg(this.Name, "MSG_TheValueMustBeDateType", new string[] { arrSwitch[i].Name }), SysVar.WarnTitle);
                                RefleshSwitchStamp();
                                return false;
                            }
                        }
                        if (strType.ToUpper() == "Numeric".ToUpper())
                        {
                            strFieldType = "N";
                            if (!BaseFunctions.IsNumeric(strValue))
                            {
                                MsgBoxEx.Show(DataFunctions.GetMsg(this.Name, "MSG_TheValueMustBeNumericType", new string[] { arrSwitch[i].Name }), SysVar.WarnTitle);
                                RefleshSwitchStamp();
                                return false;
                            }
                        }
                        #endregion
                        #region 2--check Length
                        if (strType.ToUpper() == "Char".ToUpper())
                        {
                            if (strValue.Length > intMaxLen)
                            {
                                MsgBoxEx.Show(DataFunctions.GetMsg(this.Name, "MSG_LengthValueCanNotBeGreaterThan", new string[] { arrSwitch[i].Name, intMaxLen.ToString().Trim() }), SysVar.WarnTitle);
                                RefleshSwitchStamp();
                                return false;
                            }
                        }
                        if (strType.ToUpper() == "Numeric".ToUpper())
                        {
                            strValue = BaseFunctions.FormatNumeric(strValue, "N.N").TrimEnd();
                            if (strValue.Length > intMaxLen)
                            {
                                MsgBoxEx.Show(DataFunctions.GetMsg(this.Name, "MSG_LengthValueCanNotBeGreaterThan", new string[] { arrSwitch[i].Name, intMaxLen.ToString().Trim() }), SysVar.WarnTitle);
                                RefleshSwitchStamp();
                                return false;
                            }
                        }
                        #endregion
                        #region 3 --check rules
                        #endregion
                        strSql = "update mMiscSwitch set SwitchValue='" + BaseFunctions.SpecialCharDeal(arrSwitch[i].NewValue) + "' where SwitchName= '" + arrSwitch[i].Name + "' and SystemName='" + arrSwitch[i].SwitchSys + "'";
                        dBAccess.ExecuteSql(strSql);
                        DataFunctions.SaveSwitchValueChangeToDB(dBAccess, false, arrSwitch[i].Name, arrSwitch[i].SwitchSys, arrSwitch[i].OldValue, arrSwitch[i].NewValue);
                    }
                    else //save logic switch
                    {
                        strSql = "update mSwitch set SwitchValue='" + (arrSwitch[i].NewValue.ToUpper() == "YES"? "1": "0") + "' where SwitchName= '" + arrSwitch[i].Name + "' and SwitchSys='" + arrSwitch[i].SwitchSys + "' ";
                        dBAccess.ExecuteSql(strSql);
                        DataFunctions.SaveSwitchValueChangeToDB(dBAccess, true, arrSwitch[i].Name, arrSwitch[i].SwitchSys, arrSwitch[i].OldValue, arrSwitch[i].NewValue);
                    }
                }
            }
            return true;
        }

        private void InitArrControl()
        {
            int iSwitchNum = 0;

            switch (this.CurrentMenuInfo.iParameter)
            {
                case 1:
                    iSwitchNum = intOeSwitchNum;
                    mSystemName = "Oe";
                    break;
                case 2:
                    iSwitchNum = intApSwitchNum;
                    mSystemName = "Ap";
                    break;
                case 3:
                    iSwitchNum = intArSwitchNum;
                    mSystemName = "Ar";
                    break;
                case 4:
                    iSwitchNum = intImSwitchNum;
                    mSystemName = "Im";
                    break;
                case 5:
                    iSwitchNum = intPoSwitchNum;
                    mSystemName = "Po";
                    break;
                case 6:
                    iSwitchNum = intMSwitchNum;
                    mSystemName = "M";
                    break;
                case 7:
                    iSwitchNum = intRmSwitchNum;
                    mSystemName = "Rm";
                    break;
            }

            SetControlArray(iSwitchNum);
        }

        private void SetControlArray(int iSwitchNum)
        {
            string strField = string.Empty;
            Control con = null;

            arrCon = new ArrayList(iSwitchNum);
            strField = mSystemName + "Fields";

            for (int i = 0; i < iSwitchNum; i++)
            {
                con = base.GetControl("txt" + strField + i.ToString());
                arrCon.Add(con);
                if (con != null)
                {
                    con.TextChanged +=new EventHandler(Field_TextChanged);
                    con.Leave += new EventHandler(Field_Leave);
                    con.Validating += new CancelEventHandler(Field_Validating);
                }
            }

            foreach (Control ubt in this.arraycontrols)
            {
                if (ubt.GetType().Name == "ButtonEx")
                {
                    ubt.TabStop = false;
                    ubt.Click += new EventHandler(ubtLookUp_Click);
                }
            }
        }

        private bool GetSwitchInfo(int Index)
        {
            int i = 0;
            string strSwitchName = string.Empty;
            string strSwitchSys = string.Empty;
            string strSql = string.Empty;
            DataRow drTable;
            DBAccess dBAccess = new DBAccess(false, false);

            i = Index;
            strSwitchName = arrSwitch[i].Name;
            strSwitchSys = arrSwitch[i].SwitchSys;

            if (!arrSwitch[i].IsLogic)
            {
                #region misc Switch
                strSql = "select SwitchValue,Type,MaxLength,CheckString ,RecStamp,FormatString,Description ";
                strSql+= "from mMiscSwitch where SwitchName='" + strSwitchName + "'and systemname='" + strSwitchSys + "'";
                drTable = dBAccess.GetDataFirstRow(strSql);

                if (drTable != null)
                {
                    arrSwitch[i].ValueType = drTable["Type"].ToString().TrimEnd();
                    arrSwitch[i].ValueFormat = drTable["FormatString"].ToString().TrimEnd();
                    arrSwitch[i].OldValue = BaseFunctions.FormatField(drTable["SwitchValue"].ToString().TrimEnd(), drTable["FormatString"].ToString().Trim());
                    arrSwitch[i].NewValue = arrSwitch[i].OldValue;
                    arrSwitch[i].SwitchHelp = drTable["Description"].ToString().TrimEnd() + " " + "(" + strSwitchName + ")";
                    arrSwitch[i].ValueStamp = (System.Byte[])drTable["recStamp"];
                    arrSwitch[i].ValueCheck = drTable["CheckString"].ToString().TrimEnd();
                    arrSwitch[i].MaxLength = CvtFunc.ToInt(drTable["MaxLength"].ToString());
                }
                #endregion
            }
            else
            {
                #region Logic Switch
                strSql = "select SwitchValue,SwitchDesc ,RecStamp from mSwitch ";
                strSql+= "where SwitchName='" + strSwitchName + "'and SwitchSys='" + strSwitchSys.Trim() + "'";
                drTable = dBAccess.GetDataFirstRow(strSql);

                if (drTable != null)
                {
                    if (CvtFunc.ToBoolean(drTable["SwitchValue"].ToString()))
                    {
                        arrSwitch[i].OldValue = "Yes";
                        arrSwitch[i].NewValue = "Yes";
                    }
                    else
                    {
                        arrSwitch[i].OldValue = "No";
                        arrSwitch[i].NewValue = "No";
                    }
                    arrSwitch[i].ValueType = "B";
                    arrSwitch[i].ValueStamp = (System.Byte[])drTable["recStamp"];
                    arrSwitch[i].SwitchHelp = drTable["SwitchDesc"].ToString().TrimEnd() + " " + "(" + strSwitchName + ")";
                }
                #endregion
            }

            return true;
        }

        private byte[] GetSwitchStamp(string strSwitchName, string strSys, bool blnLogic)
        {
            string strSql = string.Empty;
            byte[] btStamp = new byte[8];
            DBAccess dBAccess = new DBAccess(false, false);

            if (!blnLogic) //misc Switch
            {
                btStamp = (System.Byte[])DataFunctions.GetFieldObjectValue(dBAccess, "mMiscSwitch", "RecStamp", "SwitchName='" + strSwitchName + "'and systemname='" + strSys + "'");
            }
            else //Logic Switch
            {
                btStamp = (System.Byte[])DataFunctions.GetFieldObjectValue(dBAccess, "mSwitch", "RecStamp", "SwitchName='" + strSwitchName + "'and SwitchSys='" + strSys + "'");
            }

            return btStamp;
        }

        private bool TextCheck(int Index, ref string strErrPrompt)
        {
            bool bTextCheck = true;
            bool blnExist = false;
            int i = 0;
            Control con = null;
            Control conPrev = null;
            Control conNext = null;
            string strSql = string.Empty;
            DBAccess dBAccess = null;
            DataRow drGlAcctRange = null;

            con = arrCon[Index] as Control;
            switch (this.CurrentMenuInfo.iParameter)
            {
                case 1:
                    #region OE
                    switch (arrSwitch[Index].Name.ToUpper())
                    {
                        case "ESTFREIGHTCOSTPERMILE":
                            con.Text = BaseFunctions.FormatNumeric(con.Text,"n.2");
                            break;
                        case "DESIREGMFOREACHROUTE":
                            con.Text = BaseFunctions.FormatNumeric(con.Text, "n.0");
                            break;
                        case "DEFQUOEXPIRATION":
                            if (con.Text.Trim() == string.Empty)
                                con.Text = "0";

                            if (!BaseFunctions.IsNumeric(con.Text.Trim()))
                            {
                                bTextCheck = false;
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " is not a number !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueOfIsNotANumber", new string[] { arrSwitch[Index].Name });
                            }
                            if (CvtFunc.ToInt(con.Text.Trim()) < 0)
                            {
                                bTextCheck = false;
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " is a negative !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueOfIsANegative", new string[] { arrSwitch[Index].Name });
                            }
                            break;
                        case "O1ACCTNO": 
                        case "O2ACCTNO":
                        case "O3ACCTNO":
                        case "O4ACCTNO":
                        case "GSTACCTNO":
                        case "PSTACCTNO":
                            if (con.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "AcctNo");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                        case "O1PROFITNO":
                        case "O2PROFITNO":
                        case "O3PROFITNO":
                        case "O4PROFITNO": 
                        case "GSTPROFITNO":
                        case "PSTPROFITNO":
                            conPrev = arrCon[Index - 1] as Control;
                            if (conPrev.Text.Trim() != string.Empty && con.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "ProfitNo", "AcctNo='" + conPrev.Text + "'");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of Acct#-Profit# does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                }
                            }
                            break;
                        case "SLSPENACCTNO1":
                        case "SLSPENACCTNO2":
                            dBAccess = new DBAccess(false, false);
                            conPrev = arrCon[Index - 1] as Control;

                            #region check Balance sheet accounts
                            strSql = "select SeqNo,Name,StartAcctNo,EndAcctNo from glAccountrange ";
                            strSql+= "where SeqNo>=1 and SeqNo<=5 and '" + con.Text + "'>=StartAcctNo ";
                            strSql+= "and '" + con.Text + "'<=EndAcctNo  order by SeqNo";
                            drGlAcctRange = dBAccess.GetDataFirstRow(strSql);
                            if (drGlAcctRange != null)
                            {
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_BalanceSheetAcct");
                                bTextCheck = false;
                            }

                            if (bTextCheck)
                            {
                                strSql = "select SeqNo,Name,StartAcctNo,EndAcctNo from glAccountrange ";
                                strSql+= "where SeqNo>=1 and SeqNo<=5 and '" + conPrev.Text + "'<StartAcctNo ";
                                strSql+= "and '" + con.Text + "'>EndAcctNo  order by SeqNo";
                                drGlAcctRange = dBAccess.GetDataFirstRow(strSql);
                                if (drGlAcctRange != null)
                                {
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_BalanceSheetAcct");
                                    bTextCheck = false;
                                }
                            }
                            #endregion

                            if (bTextCheck)
                            {
                                if (conPrev.Text.Trim() != string.Empty && con.Text.Trim() != string.Empty && !(string.Compare(conPrev.Text, con.Text) <= 0))
                                {
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheEndGLAcct");
                                    bTextCheck = false;
                                }
                            }
                            break;
                        case "SLSPSTACCTNO1":
                        case "SLSPSTACCTNO2":
                            dBAccess = new DBAccess(false, false);
                            conPrev = arrCon[Index - 1] as Control;

                            #region check Balance sheet accounts
                            strSql = "select SeqNo,Name,StartAcctNo,EndAcctNo from glAccountrange ";
                            strSql+= "where SeqNo>=1 and SeqNo<=5 and '" + con.Text + "'>=StartAcctNo ";
                            strSql+= "and '" + con.Text + "'<=EndAcctNo  order by SeqNo";
                            drGlAcctRange = dBAccess.GetDataFirstRow(strSql);
                            if (drGlAcctRange != null)
                            {
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_BalanceSheetAcct");
                                bTextCheck = false;
                            }

                            if (bTextCheck)
                            {
                                if (arrSwitch[Index].Name.ToUpper() != ("SlspStAcctNo1").ToUpper())
                                {
                                    if (conPrev.Text.Trim() != string.Empty && con.Text.Trim() != string.Empty && !(string.Compare(conPrev.Text, con.Text) <= 0))
                                    {
                                        strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheRangesOfGLAcct");
                                        bTextCheck = false;
                                    }
                                }
                            }
                            #endregion
                            break;
                        case "DFLTWTUNIT":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("imUnit", BaseFunctions.SpecialCharDeal(con.Text), "Unit");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                        case "CRAPPROVALARGRACEDAY":
                            if (!(CvtFunc.ToInt(BaseFunctions.FormatNumeric(con.Text, "N")) > 0 && CvtFunc.ToInt(BaseFunctions.FormatNumeric(con.Text, "N")) <= 999))
                            {
                                bTextCheck = false;
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be positive with a maximum value of 999 days!";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueMustBePositive", new string[] { arrSwitch[Index].Name });

                            }
                            break;
                        case "CRAPPROVALTOTARAMTLATE":
                            if (!(CvtFunc.ToInt(BaseFunctions.FormatNumeric(con.Text, "N")) > 0 && CvtFunc.ToInt(BaseFunctions.FormatNumeric(con.Text, "N")) <= 999999))
                            {
                                bTextCheck = false;
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be positive with a maximum value of 999,999!";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_PositiveWithAMaximum", new string[] { arrSwitch[Index].Name });
                            }
                            break;
                        case "DEFAULTFOB":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("mFob", BaseFunctions.SpecialCharDeal(con.Text), "Description");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                        case "DEFAULTSHIPVIA":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("arShipVia", BaseFunctions.SpecialCharDeal(con.Text), "ViaDesc");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                        case "REMNO":
                        case "REMNO1":
                        case "REMNO2":
                            if (CvtFunc.ToInt(BaseFunctions.FormatNumeric(con.Text, "n.n")) != 0)
                            {
                                blnExist = DataFunctions.CheckRecordExist("oeRecurringRemark", BaseFunctions.SpecialCharDeal(con.Text), "RemNo");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                        case "DFTTSOSALESTERMS":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("arTerm", BaseFunctions.SpecialCharDeal(con.Text), "TermDesc");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                        case "dftBottleLinesinDotMatrix":
                            if (!BaseFunctions.IsNumeric(con.Text))
                                strErrPrompt = "Must be numeric.";
                            break;
                    }
                    break;
                    #endregion
                case 2:
                    #region AP
                    switch (arrSwitch[Index].Name.ToUpper())
                    {
                        case "AGING1":
                            if (con.Text != string.Empty && CvtFunc.ToInt(con.Text) < 1)
                            {
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be greater than 0 !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_ValueMustGreaterThanZero", new string[] { arrSwitch[Index].Name });
                                bTextCheck = false;
                            }
                            break;
                        case "AGING2":
                        case "AGING3":
                        case "AGING4":
                            conPrev = arrCon[Index - 1] as Control;
                            if (CvtFunc.ToInt(conPrev.Text) > CvtFunc.ToInt(con.Text))
                            {
                                //strErrPrompt = "The value of the aging column is less than the column before !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AgingColLess");
                                bTextCheck = false;
                            }
                            break;
                        case "ACCRUALDIFFTACCTNO":
                            conNext = arrCon[Index + 1] as Control;
                            if (con.Text.Trim() != string.Empty && conNext.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "AcctNo", "ProfitNo='" + conNext.Text + "'");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                }
                            }
                            break;
                        case "ACCRUALDIFFPROFITNO":
                            conPrev = arrCon[Index - 1] as Control;
                            if (conPrev.Text.Trim() != string.Empty && con.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "ProfitNo", "AcctNo='" + conPrev.Text + "'");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                }
                            }
                            break;
                        case "FREIGHTACCRUALDIFFTACCTNO":
                            conNext = arrCon[Index + 1] as Control;
                            if (con.Text.Trim() != string.Empty && conNext.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "AcctNo", "ProfitNo='" + conNext.Text + "'");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                }
                            }
                            break;
                        case "FREIGHTACCRUALDIFFPROFITNO":
                            conPrev = arrCon[Index - 1] as Control;
                            if (conPrev.Text.Trim() != string.Empty && con.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "ProfitNo", "AcctNo='" + conPrev.Text + "'");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                }
                            }
                            break;
                        case "QSTACCTNO":
                            conNext = arrCon[Index + 1] as Control;
                            if (con.Text.Trim() != string.Empty && conNext.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "AcctNo", "ProfitNo='" + conNext.Text + "'");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                }
                            }
                            break;
                        case "QSTPROFITNO":
                            conPrev = arrCon[Index - 1] as Control;
                            if (conPrev.Text.Trim() != string.Empty && con.Text.Trim() != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "ProfitNo", "AcctNo='" + conPrev.Text + "'");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                }
                            }
                            break;
                        case "GSTINPACCTNO":
                            conNext = arrCon[Index + 1] as Control;
                            if (!bClientInUSA)
                            {
                                if (con.Text.Trim() != string.Empty && conNext.Text.Trim() != string.Empty)
                                {
                                    blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "AcctNo", "ProfitNo='" + conNext.Text + "'");
                                    if (!blnExist)
                                    {
                                        bTextCheck = blnExist;
                                        strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                    }
                                }
                            }
                            break;
                        case "GSTINPPROFITNO":
                            conPrev = arrCon[Index - 1] as Control;
                            if (!bClientInUSA)
                            {
                                if (conPrev.Text.Trim() != string.Empty && con.Text.Trim() != "")
                                {
                                    blnExist = DataFunctions.CheckRecordExist("glAccount", con.Text, "ProfitNo", "AcctNo='" + conPrev.Text + "'");
                                    if (!blnExist)
                                    {
                                        bTextCheck = blnExist;
                                        strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AcctNoProfitNoNotExist");
                                    }
                                }
                            }
                            break;
                        case "LUMBERSUPPLIERTYPE":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("apType", BaseFunctions.SpecialCharDeal(con.Text), "TypeNo");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " " + "does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", arrSwitch[Index].Name);
                                }
                            }
                            break;
                        case "TRUCKINGFIRMTYPE":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("apType", BaseFunctions.SpecialCharDeal(con.Text), "TypeNo");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " " + "does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", arrSwitch[Index].Name);
                                }
                            }
                            break;
                    }

                    if (!bTextCheck)
                        con.Focus();
                    break;
                    #endregion
                case 3:
                    #region AR
                    switch (arrSwitch[Index].Name.ToUpper())
                    {
                        case "AGEINGDAY01":
                            if (con.Text != string.Empty && CvtFunc.ToInt(con.Text) < 1)
                            {
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be greater than 0 !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_ValueMustGreaterThanZero", new string[] { arrSwitch[Index].Name });
                                bTextCheck = false;
                            }
                            break;
                        case "AGEINGDAY02":
                        case "AGEINGDAY03":
                        case "AGEINGDAY04":
                            conPrev = arrCon[Index - 1] as Control;
                            if (CvtFunc.ToInt(conPrev.Text) > CvtFunc.ToInt(con.Text))
                            {
                                //strErrPrompt = "The value of the aging column is less than the column before !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_AgingColLess");
                                bTextCheck = false;
                            }
                            break;
                        case "DFLTCUSTGROUPNO":
                            if (con.Text.Trim() != "")
                            {
                                blnExist = DataFunctions.CheckRecordExist("arGroup", BaseFunctions.SpecialCharDeal(con.Text), "GroupNo");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    if (Customize.IsNuPro())
                                    {
                                        strErrPrompt = "Customer Channel number does not exist!";
                                    }
                                    else
                                    {
                                        strErrPrompt = Msg.Select("Customer group number does not exist!", DataFunctions.GetMsg(this.Name, "MSG_CustGgroupNoNotExist"));
                                    }
                                    //strErrPrompt = "Customer group number does not exist!";
                                    //DataFunctions.GetMsg(this.Name, "MSG_CustGgroupNoNotExist");
                                }
                            }
                            break;
                        case "ANNUALINVRATE":
                        case "ANNUALINTERESTRATE":
                            if (!(CvtFunc.ToDouble(BaseFunctions.FormatNumeric(con.Text, "n.2")) > 0 && 
                                  CvtFunc.ToDouble(BaseFunctions.FormatNumeric(txtArFields8.Text, "n.2")) <= 99.99))
                            {
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be greater than 0 and smaller than 99.99 !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueGreaterThanZeroAndSmaller", new string[] { arrSwitch[Index].Name });
                                bTextCheck = false;
                            }
                            break;
                        case "GRACEDAYSCUSTINVDISC":
                            if (!(CvtFunc.ToDouble(BaseFunctions.FormatNumeric(con.Text, "n.2")) > 0))
                            {
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be greater than 0 !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_ValueMustGreaterThanZero", new string[] { arrSwitch[Index].Name });
                                bTextCheck = false;
                            }
                            break;
                        case "REMITTONO":
                            if (!(DataFunctions.CheckRecordExist("mRemitTo", con.Text, "RemitToNo")))
                            {
                                strErrPrompt="RemitTo# not exist.";
                                bTextCheck=false;
                            }
                            break;
                    }

                    if (!bTextCheck)
                        con.Focus();
                    break;
                    #endregion
                case 4:
                    #region IM
                    switch (arrSwitch[Index].Name.ToUpper())
                    {
                        case "NUMBEROFPRICES":
                            if (!(CvtFunc.ToInt(con.Text) >= 1 && CvtFunc.ToInt(con.Text) <= 10))
                            {
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be 1 to 10 !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueMustBeOneToTen", new string[] { arrSwitch[Index].Name });
                                bTextCheck = false;
                            }
                            break;
                        case "PRODCATGLEVEL":
                            if (!(CvtFunc.ToInt(con.Text) >= 1 && CvtFunc.ToInt(con.Text) <= 8))
                            {
                                //strErrPrompt = "The value of " + arrSwitch[Index].Name + " must be 1 to 8 !";
                                strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueMustBeOneToEight", new string[] { arrSwitch[Index].Name });
                                bTextCheck = false;
                            }
                            break;
                    }
                    break;
                    #endregion
                case 5:
                    #region PO
                    switch (arrSwitch[Index].Name.ToUpper())
                    {
                        case "DEFAULTFOB":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("mFob", BaseFunctions.SpecialCharDeal(con.Text), "Description");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                        case "DEFAULTSHIPVIA":
                            if (con.Text != string.Empty)
                            {
                                blnExist = DataFunctions.CheckRecordExist("arShipVia", BaseFunctions.SpecialCharDeal(con.Text), "ViaDesc");
                                if (!blnExist)
                                {
                                    bTextCheck = blnExist;
                                    //strErrPrompt = "The value of " + arrSwitch[Index].Name + " does not exist !";
                                    strErrPrompt = DataFunctions.GetMsg(this.Name, "MSG_TheValueNotExist", new string[] { arrSwitch[Index].Name });
                                }
                            }
                            break;
                    }
                    break;
                    #endregion
                case 6:
                    #region MF
                    break;
                    #endregion
                case 7:
                    #region RM
                    break;
                    #endregion
            }

            return bTextCheck;
        }

        private bool ValidCheck()
        {
            bool bValidCheck = false;
            string strErrPrompt = string.Empty;
            int i = 0;

            for (i = 0; i< arrSwitch.Length; i++)
            {
                if (arrSwitch[i].NeedValidCheck)
                {
                    bValidCheck = TextCheck(i, ref strErrPrompt);
                    if (!bValidCheck)
                    {
                        MsgBoxEx.Show(strErrPrompt, SysVar.WarnTitle);
                        return bValidCheck;
                    }
                }
            }
            return bValidCheck;
        }
        private void RefleshSwitchStamp()
        {
            int i = 0;
            byte[] btStamp = new byte[8];

            for (i = 0; i<arrSwitch.Length; i++)
            {
                btStamp = GetSwitchStamp(arrSwitch[i].Name, arrSwitch[i].SwitchSys, arrSwitch[i].IsLogic);
                arrSwitch[i].ValueStamp = btStamp;
            }
        }

        public string CnvStampToStr(byte[] btStamp, string strDeli)
        {
            //Function: convert the Stamp to a string delimetered by strDeli
            //Output:   String devided by strDeli
            //Special:  the varStamp should be  byte(0 to 7)

            string strStamp = string.Empty;
            int i = 0;
            int iDeliPos = 0;

            for (i = 0; i< 8; i++)
            {
                strStamp += btStamp[i] + strDeli;
            }

            //delete last strDeli
            strStamp = strStamp.Remove(strStamp.Length - 1);
            return strStamp;
        }
        #endregion


    }
}